<template>
  <maincontainer>
    <mycard>
      <searchform :formList='formList' :formValue='formValue'>
        <template #action>
          <n-button @click='handleSearch'>查询</n-button>
          <n-button @click='handleResetForm'>重置</n-button>
          <n-button @click='handleCreate'>新建</n-button>
        </template>
      </searchform>
    </mycard>
    <mycard class='flex-1 h-full'>
      <flextable :column='column' :tabledata='tableData'></flextable>
    </mycard>
    <mycard class='w-full h-8 juzhong1'>
      <fenye :total='total' @change='gettabledatafunc' ref='fenyeref' class='juzhong1'></fenye>
    </mycard>
    <Model ref='editref' @close='refreshdelete'></Model>
  </maincontainer>
</template>

<script setup name='Myricheng' lang='ts'>
import { useRoute, useRouter } from 'vue-router'
import Model from './model.vue'
import { DefineComponent, h, inject, ref } from 'vue'
import { useListIndex } from '../../../hooks/useEdit'
import { useColumns } from '../../../hooks/useColumns'

const router = useRouter()
const route = useRoute()
const {
  formRef, fenyeref, editref, formValue, tableData, total, handleSearch,
  handleResetForm, handleView, handleEdit, handleCreate, refreshdelete,http,message,loading,
} = useListIndex()

// 点击删除
let delDialog: Function = inject('delDialog')
const handleDelete = (data: any) => {
  delDialog(refreshdelete, null, data.id, data.name)
}

const { index, createdTime, changeTime, view, edit, del } = useColumns(handleView, handleEdit, handleDelete)
const column = ref([
  index,
  { title: '名称', key: 'name', show: true },
  { title: '编码', key: 'code', show: true },
  { title: '所属上级', key: 'parent', show: true },
  createdTime, changeTime, view, edit, del,
])
const formList = ref([
  {
    label: '资产名称',
    key: 'name',
    type: 'input',
    rules: [],
  },
  {},
  {},
  {
    slot: 'action',
  },
])

// 向后台获取数据
const gettabledatafunc = () => {
}
const zhucefunc:Function|undefined = inject("zhuceshuaxinfunc")
// 初始化函数
const init = () => {
  fenyeref.value && fenyeref.value.changeoption({page:1})
}

// 初始化区域
init()
zhucefunc && zhucefunc({[route.name!.toString()]:init})
</script>


<style scoped>
</style>
